<?php 
if(KT!='KhiThe') exit;
class scarts_model extends khithe_mysql{

	public function setCheckedshoppingcarts($ID,$Val)
	{
		$ID = parent::checkStrMySQL($ID);
		$update = "UPDATE ".shoppingcarts." SET Status='".$Val."'  WHERE ID = '".$ID."'";
		$update_qr = parent::UpdateInsertMySQL($update);
		parent::CloseConnection();
		return $update_qr;
	}
	
	public function delCheckedshoppingcarts($ID)
	{
		$ID = parent::checkStrMySQL($ID);
		$del = "DELETE FROM ".shoppingcarts." WHERE ID='".$ID."' ";
		$del_detail = "DELETE FROM ".shoppingcarts_detail." WHERE ShopingCartID='".$ID."' ";
		$del_qr = parent::DeleteMySQL($del);
		$del_qr = parent::DeleteMySQL($del_detail);
		parent::CloseConnection();
		return $del_qr;
	}
	
	public function getSqlshoppingcarts($page,$limit)
	{
		if($limit!=''){
			$page=($page==''?1:$page);
			$start = ($page - 1)* $limit; 
			$strlimit = "LIMIT $start, $limit";
		}
		else{
			$strlimit ='';
		}
		
		$select = "SELECT * FROM ".shoppingcarts." ORDER BY ID DESC ".$strlimit." ";
		return parent::SelectMySQL($select);
	}
	
	public function selectshoppingcart($ID)
	{
		$ID = parent::checkStrMySQL($ID);
		$select = "SELECT * FROM ".shoppingcarts." WHERE ID = '".$ID."'";
		$query = parent::SelectMySQL($select);
		$row = mysql_fetch_assoc($query);
			
		return $row;
	}
	
	public function getListProduct($ShopingCartID)
	{	
		$ShopingCartID = parent::checkStrMySQL($ShopingCartID);
		$select = " SELECT ".shoppingcarts.".ID AS SID, ".shoppingcarts.".*, ".shoppingcarts_detail.".*,  ".products.".Title
					FROM   ".shoppingcarts.",   ".shoppingcarts_detail.",    ".products." 
					WHERE 	".shoppingcarts.".ID = ".shoppingcarts_detail.".ShopingCartID AND
							".shoppingcarts_detail.".ShopingCartID = '".$ShopingCartID."' AND
							".products.".ID = ".shoppingcarts_detail.".ProductID 
							 ";
		return $query = parent::SelectMySQL($select);	
	}
	
	public function setStatusCarts($ID,$Val)
	{
		$ID = parent::checkStrMySQL($ID);
		$update = "UPDATE ".shoppingcarts." SET Process='".$Val."'  WHERE ID = '".$ID."'";
		$update_qr = parent::UpdateInsertMySQL($update);
		parent::CloseConnection();
		return $update_qr;
	}
}
?>